package com.droidblackbox.receiver;

import com.droidblackbox.manager.SystemManager;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class InternetStateReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		ConnectivityManager connectivityManager = (ConnectivityManager) context
				.getSystemService(Context.CONNECTIVITY_SERVICE);

		NetworkInfo wifi = connectivityManager
				.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

		NetworkInfo mobile = connectivityManager
				.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

		NetworkInfo wibro = connectivityManager
				.getNetworkInfo(ConnectivityManager.TYPE_WIMAX);

		if (mobile.isConnected() || wifi.isConnected() || wibro.isConnected()) {
			SystemManager.getInstance().setInternet(true);
			SystemManager.getInstance()
					.showToast(context, "Internet Connected");
		} else {
			SystemManager.getInstance().setInternet(false);
			SystemManager.getInstance().showToast(context,
					"Internet Disconnected");
		}

	}
}
